package com.hjy.controller;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@WebServlet(name = "s1",value = "/s1")
public class Servlet01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setHeader("Refresh", "5");
        ServletContext context = request.getServletContext();
        context.getRealPath("/WEB-INF/classes/腾讯.png");
        // /代表根目录(当前项目或模块的目录)
        InputStream resourceAsStream = context.getResourceAsStream("/WEB-INF/classes/user.properties");
        Properties properties = new Properties();
        properties.load(resourceAsStream);
        String username = properties.getProperty("username");
        String password = properties.getProperty("password");
        System.out.println(username + ":"+password);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
